package com.hunters.web.wechat.entity.model;

import com.platform.common.util.StringUtils;
import lombok.Data;

import java.util.List;

/**
 * @program: web-wechat
 * @description:
 * @author: 李二
 * @create: 2018/09/05 17:10
 **/
@Data
public class LoginSession {
    private User user;

    private List<Account> contactList;//好友列表

    private String url;

    private String fileUrl;

    private String syncUrl;

    private String deviceId;

    private String sKey;

    private String wxSid;

    private String wxUin;

    private String passTicket;

    private String syncKeyStr;

    private Integer inviteStartCount;

    private BaseRequest baseRequest;

    private SyncKey syncKey;

    private boolean success;

    public String getSyncOrUrl() {
        if (StringUtils.isNotEmpty(this.syncUrl)) {
            return this.syncUrl;
        }
        return this.url;
    }

    public String getFileUrl() {
        if (StringUtils.isNotEmpty(this.fileUrl)) {
            return this.fileUrl;
        }
        return this.url;
    }

    public void setSyncKey(SyncKey syncKey) {
        this.syncKey = syncKey;

        StringBuilder syncKeyBuf = new StringBuilder();
        for (KeyItem item : syncKey.getList()) {
            syncKeyBuf.append("|").append(item.getKey()).append("_").append(item.getVal());
        }
        if (syncKeyBuf.length() > 0) {
            this.syncKeyStr = syncKeyBuf.substring(1);
        }
    }
}
